﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace OutputHelper
{
    public class OutputHelper
    {
        private static string outputPath = @"D:\Work\Doctorat\My Work\dot net\jMetal.net\Output";

        private static OutputHelper _instance;

        public static OutputHelper Instance
        {
            get { return _instance ?? (_instance = new OutputHelper()); }
        }

        public string Problem { get; set; }
        public string Algorithm { get; set; }


        private string myOutputPath;
        public string OutputPath
        {
            get
            {
                if (string.IsNullOrEmpty(myOutputPath))
                {
                    myOutputPath = Path.Combine(outputPath, Problem + " " + Algorithm);
                    if (!Directory.Exists(myOutputPath))
                    {
                        Directory.CreateDirectory(myOutputPath);
                    }
                }
                return myOutputPath;
            }
        }

        private string _currentDir;

        public string CurrentDir
        {
            get
            {
                if(string.IsNullOrEmpty(_currentDir))
                {
                    SetCurrentDir();
                }
                return _currentDir;
            }
        }

        public void SetCurrentDir()
        {
            _currentDir = Path.Combine(OutputPath, DateTime.Now.Ticks.ToString());
            Directory.CreateDirectory(_currentDir);
            Directory.SetCurrentDirectory(_currentDir);
        }
    }
}
